
 var information={
    currentPage:1,	
  	totalPage:1,
  	pageSize:10,
  };
 var chooseId=0;
$(function(){
  var endId=[];
  var insertid;
  var deleteid;
  initTaskDis();
  requestSort();
  requestRefer(information);//已提交数据
  //跳转到详情界面
  $(document).on("click",".detail",function(){
	  var id= $(this).attr("data-id");
		var menuId=$("#menu-container").attr("menu-id");
		window.location.href = '../information/subDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
  })


 

  
  $(document).on("click",".input-task-finsh-context",function(){
	  var account=$(this).attr("data-account");
	  var taskId=$(this).attr("data-taskId");
	  var id=$(this).attr("data-id");
	  $("#modal-input-task-finsh-context").modal("show");	 
	  $("#modal-infoAccount").attr("placeholder","信息编号:"+id);
	  $("#input-task-finsh-btn").attr("data-id",id);
	  $("#input-task-finsh-btn").attr("data-taskId",taskId);
	 // $("#modal-input-context").text();
  })
 
  $("#input-task-finsh-btn").click(function(){
	  var id=$(this).attr("data-id");
	  var taskId=$(this).attr("data-taskId");
	  var context=$("#modal-input-context").val();
	  YuXi.util.get("TaskFinshFilter/inputTaskFinshContext.do",{inforId:id,taskId:taskId,context:context},function(data){
		  $("#modal-input-task-finsh-context").modal("hide");	 
		  myTool.alert({
			 title:"提示",
			 context:data.msg
		 });
	  },function(){
		  myTool.alert({
				 title:"提示",
				 context:"未知错误"
			 });
	  });
	  
  });
  
  
  $(document).on("click",".insert-task",function(){
	  insertid="infoId="+$(this).attr("data-id");
	  $("#Mymodal").modal('show');
  });
  //提交模态框按钮
  $("#btnSure").click(function(){	
	  requestSure(insertid);//调用提交方法;
  })

  //分页，首页
  $("#headPage").click(function(){
	information.currentPage=1;
  	$("#totalPage").html(information.currentPage+"/"+information.totalPage);
  	requestRefer(information);
  })
  

  //分页，尾页
  $("#endPage").click(function(){
  	$("#totalPage").html(information.totalPage+"/"+information.totalPage);
  	information.currentPage=information.totalPage;
  	requestRefer(information);
  })
  //分页，上一页
  $("#prevPage").click(function(){
  	if(information.currentPage<=1)
  	{
  		information.currentPage=1;
  	}
  	else
  	{
  		information.currentPage=information.currentPage-1;
  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);  
  		requestRefer(information);
  	}

 })
 
  //分页，下一页
   $("#nextPage").click(function(){
  	
  	if(information.currentPage>=information.totalPage)
  	{
  		information.currentPage=information.currentPage;
  	}
  	else
  	{
  		information.currentPage=information.currentPage+1;
  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);
  		requestRefer(information);
  	}
  	
  })
  
})

//提交按钮
function requestSure(id)
{
	  alert(id);
	  var url="TaskDispatchFilter/taskSubToTaskFinish.do";//提交的地址
	  YuXi.util.get(url,id,function(data){
		  if(data.status)
		  {
			  $("#successmodel").modal('show');
		  }
		  else
		  {
			 
			  $("#badmodal").modal('show');
		  }
	  },function(){
		  $("#badmodal").modal('show');
	  })
}

//向后台请求的信息数据
function requestRefer(data){
	var url="getUserInputTaskContext.do";
	YuXi.util.get(url,data,function(data){	 
		object=data.list;
		information.totalPage=data.totalPage;
		information.page=data.currentPage;
		$("#totalPage").html(information.page+"/"+information.totalPage);
		$("#table1body").html("");
		for(var i=0;i<object.length;i++)
		{
			if( object[i].informationProfile.length>15)
				object[i].informationProfile= object[i].informationProfile.substring(0,15)+"...";
			var time=YuXi.getTime.get(object[i].zeRenTime*1);
			var remark=object[i].remark;
			if(remark==undefined||remark==null){
				remark="";
			}
			var html="<tr ><td>"+ object[i].informationAccount+"</td><td >"+object[i].informationProfile+"</td>"+
			
			"<td >"+object[i].informationClassificationNames+"</td>+" +
			"<td >"+object[i].informationSourceNames+"</td>"+
			"<td >"+object[i].safetyPortNames+"</td>"+
			"<td >"+object[i].personDispatchName+"</td>"+
			"<td >"+time+"</td>"+
			"<td >"+remark+"</td>"+
			"<td><a href='javascript:void(0);' data-id="+object[i].id +" class='detail'>详情</a>&nbsp;&nbsp;</td></tr>";
			
			$("#table1body").append(html);
		}
		
		YuXi.graded.get();
	},function(){});
  

}
$("#firstSearch").click(function(){
	firstSearch();
});
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{
	information={};
		information.key = $("#profile").val(); //简介
		if($("#profile").val()=="请输入简介关键字")
		{
			information.key="";
		}
		information.informationLv = $(".reSearchpes option:selected").val() //分级
		information.informationSort = $(".reSearchsort option:selected").val() //分类
		information.informationSource = $(".reSearchSource option:selected").val() //来源渠道
		var curFlowText = $(".reSearchFlow option:selected").val();
		curFlowText == null ? "" : information.curFLow = curFlowText; //当前流程
		information.safetyPortId=$(".rePort option:selected").val();//分口
		information.informationJudge=$(".repingjia option:selected").val();//评价
		var inputNameFlag=$("#requestName").val();//参与人
		if(inputNameFlag=="请输入参与人姓名或警号")
		{
			information.intputName="";
		}
		else
		{ 
			var flag=/^[(-?\d+\.\d+)|(-?\d+)|(-?\.\d+)]+$/.test(inputNameFlag + '');
			
			if(!flag)
			{
				information.intputName=inputNameFlag;
			}
			else
			{
				information.intputNumber=inputNameFlag;
			}
		}
		var finishNameFlag=$("#refinishName").val();//完成人
		if(finishNameFlag=="请输入派遣人姓名或警号")
		{
			information.finisPerson="";
		}
		else
		{ 
			var flag=/^[(-?\d+\.\d+)|(-?\d+)|(-?\.\d+)]+$/.test(finishNameFlag + '');
			
			if(!flag)
			{
				information.finisPerson=finishNameFlag;
			}
			else
			{
				information.finisPersonNum=finishNameFlag;
			}
		}
		information.structure=$(".reDepartment option:selected").val();//部门
		information.qualityId=$(".reinputDian option:selected").val();//录入点评
		information.completeId=$(".refinishDian option:selected").val();//完成点评
		var array=[];
		var starTime="";	
		var endTime="";
		starTime=$("#submitstarTime").val();//提交起始时间
		endTime=$("#submitendTime").val();//提交结束时间
		array = YuXi.timestamp.get(starTime,endTime, null);
		if(array[0]!=null)
		information.startFinishTime = array[0];
		if(array[1]!=null)
		information.endFinishTime = array[1];
	

		
		

		starTime=$("#starTime").val();//建立起始时间
		endTime=$("#endTime").val();//建立结束时间
		array = YuXi.timestamp.get(starTime,endTime, null);
		if(array[0]!=null)
		information.startTimestamp = array[0];
		if(array[1]!=null)
		information.endTimestamp = array[1];
		information.flowId=2;
		information.currentPage=1;	
		////console.log(JSON.stringify(information));
	requestRefer(information);
	
	
}

function initTaskDis(){
	 YuXi.util.get("getAllInformationClassification.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchpes").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	
	 
	 YuXi.util.get("getAllInformationPort.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".task-port").append("<option value='"+obj[i].id+"' >"+obj[i].portName+"</option>");
			 }
			 
		 }
	 });
	
}

function requestSort(){	
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".reSearchsort").append(html);
		}
	},function(){
		
	});//请求数据
	
	}
